import pymysql

def main():
    con = pymysql.connect(host='192.168.3.11',port=3306,db='hrs',user='root',password='123')
    sel = input('请输入功能')
    try:
        with con.cursor() as cursor:
            if sel == '1':
                update1(cursor)
            elif sel == '2':
                select1(cursor)
            else:
                insert1(cursor)
            con.commit()
    except pymysql.MySQLError as error:
        con.rollback()
        print(error)
    finally:
        con.close()
def update1(cursor):
    no = input('请输入员工编号:')
    cursor.execute('update tb_emp set sal=10000 where eno=%s;',(no,))
def select1(cursor):
    no = ('eno','ename','sal')
    cursor.execute('select eno from tb_emp order by eno desc;')
    print(cursor.fetchall())
def insert1(cursor):
    line = input('请输入插入的一行值，以逗号分割：')
    line_tuple = (i.strip() for i in line.split(','))
    print(line_tuple)
    cursor.execute('insert into tb_emp values (%s,%s,%s,%s,%s,%s,%s,%s);',line_tuple)


if __name__ == '__main__':
    main()
    # line = input('请输入插入的一行值，以逗号分割：')
    # line_tuple = (i.strip() for i in line.split(','))
    # print(tuple(line_tuple))